﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace IVisual._SC
{
    /// <summary>
    /// Stellt Methoden zur XML-serialisirung der Config zu verfügung
    /// </summary>
    public class cls_Config
    {
        /// <summary>
        /// Speichert ein Objekt in eine XML-File
        /// </summary>
        /// <param name="file">Pfad zum speichern</param>
        /// <param name="c">Objekt zum speichern</param>
        public static void Serialize(string file, object c)
        {
            System.Xml.Serialization.XmlSerializer xs
               = new System.Xml.Serialization.XmlSerializer(c.GetType());
            StreamWriter writer = File.CreateText(file);
            xs.Serialize(writer, c);
            writer.Flush();
            writer.Close();
        }

        /// <summary>
        /// Stellt ein Objekt aus einem XML-File wieder her
        /// </summary>
        /// <param name="file">Pfad zur Datei</param>
        /// <param name="t">Typ des enthaltenen Objekts</param>
        /// <returns>Objekt</returns>
        public static object Deserialize(string file, Type t)
        {
            System.Xml.Serialization.XmlSerializer xs
               = new System.Xml.Serialization.XmlSerializer(t);
            StreamReader reader = File.OpenText(file);
            object c = xs.Deserialize(reader);
            reader.Close();
            return c;
        }
    }
}
